package com.example.myapplication.ui.activity.question

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.request.CollectRequest
import com.example.myapplication.request.QuestionRequest
import kotlinx.coroutines.launch

/**
 *问答的viewModel
 *
 * @author : Kun
 * @date : 2021/6/10
 * @time : 15:32
 */
class QuestionViewModel : ViewModel() {
    /**
     * 问答的adapter
     */
    val questionRequest = QuestionRequest()
    /**
     * 收藏相关的request
     */
    val collectRequest = CollectRequest()

    /**
     *请求问答数据
     */
    fun requestQuestion(index: Int) {
        viewModelScope.launch {
            questionRequest.requestQuestion(index)
        }
    }

    /**
     * 新增文章收藏
     */
    fun requestAddCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestAddCollectArticle(id)
        }
    }

    /**
     * 取消文章收藏
     */
    fun requestDelCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestDelCollectArticle(id)
        }
    }
}